/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: Direcotry.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/11 上午9:24
 * LastModified: 2020/03/11 09:24:11
 */

package com.qolome.knowledge.design.pattern.composite.demo.safe;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qolome
 * @version V1.0
 * @Description 文件夹
 * @date 2020年 03月11日 09:24:15
 */
@Slf4j
public class Folder extends Direcotry{


    private List<Direcotry> direcotries;
    private Integer level;


    public Folder(String name, Integer level) {
        super(name);
        this.level = level;
        this.direcotries = new ArrayList<>();
    }


    @Override
    public void show(){
        log.info("name:{}", name);
        log.info("level:{}", level);
        printLine(level);
        for (Direcotry direcotry : direcotries) {
            direcotry.show();
        }
    }

    public void list(){
        for (Direcotry direcotry : direcotries) {
          log.info("file name:{}",direcotry.name);
        }

    }

    public boolean add(Direcotry direcotry){
        return this.direcotries.add(direcotry);
    }

    public boolean remove(Direcotry direcotry){
        return this.direcotries.remove(direcotry);
    }

    public Direcotry get(int index){
        return this.direcotries.get(index);
    }

    private void printLine(int level) {
        if (level != 0) {
            StringBuilder printPath = new StringBuilder();
            for (int i = 0; i < level; i++) {
                printPath.append("/--");
            }
            log.info(printPath.toString());
        }
    }

}
